Enterprise Objects Framework Release 1.1 Copyright ã1995 by NeXT Computer, Inc.  All Rights Reserved.

EOAssociationNotification 

Adopted By:	EOAssociation

Declared In:	eointerface/EOController.h

Protocol Description

The EOAssociationNotification protocol declares methods sent by an EOController to tell its EOAssocations about changes to its enterprise objects. Whenever an object is modified by a controller, whether by being inserted, deleted, or updated, the controller sends each of its EOAssociations a contentsDidChange message, allowing the association to display any new values. If the change to the controller also involves a change of selection, it sends selectionDidChange to each association, so that the association can display values for the proper object, or highlight the selected objects if its user interface object displays multiple values.

The controller also informs its associations when an operation it's performing would invalidate any cached values for the user interface objects. When the controller saves or discards its buffered edits, it renders any edited values cached by its associations irrelevantÐand so it sends each association a discardEdits message. For example, an NXTableView doesn't actually store the values it displays, but gets them through another object, such as an EOColumnAssociation. The association object actually stores any edited values for the column, and discardEdits informs the association that the cached values it has are no longer applicable.

Any other operation the controller performsÐfetching, inserting a new object, setting an undo markÐrequires editing of a user interface object to end.  In this case, the controller sends endEditing to each of its associations, so that they can finish editing, reclaim any shared resources (such as a window's field editor), and notify the controller with associationDidEdit:.

Implementing the EOAssociationNotification Protocol

The descriptions in this specification provide all the details of what the methods should do, but there are a few issues in implementing them that you need to be aware of. Because an association not only receives messages from its controller, but sends them to its controller as well, a recursive loop could result if your association subclass sends messages back to its controller from one of the notification methods of this protocol. For example, if your association needs to alter the controller's selection in its own selectionDidChange message, it will be sent another selectionDidChange message while still handling the first. You should either implement your association not to affect the controller's selection or values, or you should devise a mechanism for preventing the association notification methods from being recursively invoked.

Another slight consideration stems from the intimate relationship between an association and its user interface object. An association is usually so simple, and its implementation so tied to the specific behavior of its user interface object class, that it's usually easier to implement a new association as a subclass of EOAssociation rather than one of its subclasses.

Method Types

Synchronizing values	- contentsDidChange
- selectionDidChange

Handling edits	- discardEdits
- endEditing

Instance Methods

contentsDidChange

- (void)contentsDidChange 

Sent to an EOAssociation by its controller whenever the controller's objects have changed; for example, when an object is edited, inserted, or deleted, or when the controller performs a fetch operation. The association should determine whether any values it's responsible for have changed, and if so should update its user interface object.

An association may be sent both a contentsDidChange and a selectionDidChange method for a single change in the controller.  For example, if a selected object is deleted, both the contents and the selection change.

discardEdits

- (void)discardEdits 

An EOController sends this method to its controllers before fetching, to notify them that any edited values they cache for their user interface objects should be disposed of.

endEditing

- (void)endEditing 

Informs the EOAssociation that it should formally end any editing in its user interface object and inform the controller of any pending edit by sending associationDidEdit:. This also usually results in the user interface object resigning first responder.

See also:  - endEditingFor: (Window class of the Application Kit)

selectionDidChange

- (void)selectionDidChange 

Sent to an EOAssociation by its controller whenever the controller's selection indexes have changed. The association should have its user interface object redisplay itself to reflect the change in selection. For a user interface object that displays a single value, the association sets that object's value to the property value for the first selected object in the controller. For a user interface object that displays multiple values, the association has the object highlight its values in accordance with the selection.

An association may be sent both a contentsDidChange and a selectionDidChange method for a single change in the controller.  For example, if a selected object is deleted, both the contents and the selection change.